package com.tbvtc.agriculturalcreditchainserver2025.utils.Block;

import org.springframework.core.io.ClassPathResource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class AbiFileReader {

    public static String readAbiFile(String fileName) {
        StringBuilder content = new StringBuilder();
        try {
            // 使用 ClassPathResource 来加载 resources 目录下的文件
            ClassPathResource resource = new ClassPathResource("abi/" + fileName);
            try (InputStream inputStream = resource.getInputStream();
                 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    content.append(line).append("\n");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content.toString();
    }

    public static void main(String[] args) {
        String abiContent = readAbiFile("FarmerManagement.abi");
        System.out.println(abiContent);
    }
}